﻿using ImageUploader;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using DataLibrary;
using System.Linq;

namespace Common
{
    public class MonitorFile
    {
        private static ListBox list_Info;
        private static ListBox list_Error;
        private static FileSystemWatcher watcher;
        private static Hashtable htCode;
        private static Hashtable htFileList = new Hashtable();
        private static List<string> CheckList;
        private static object obj=new object(); 
        private static Thread threadMonitor = null;
        private static Thread threadBulk = null;
        private static Thread threadBulk2 = null;
        private static Thread threadBulk3 = null;
        private static Thread threadBulk4 = null;
        private static Thread threadCheck = null;
        private static string imagePath;
        private static int operationFlag = 0;
        private static TextBox txt_Num;
        public delegate void GetNumberCallBack(TextBox txt_Num, int _num, string remark);
        private static int num = 0;
        private static int cnt = 1;
        private static int total = 0;

        private static int time = 1;
        private static int times = 0;
        private static FtpArg ftpArg;
        public static void getNumber(TextBox txt, int _num, string remark = "")
        {
            _num = num;
            if (txt.InvokeRequired)
            {
                GetNumberCallBack getNumberCallBack = getNumber;
                txt.Invoke(getNumberCallBack, new object[] { txt, _num, remark });
            }
            txt.Text = _num.ToString() + remark;
        }
        public static void monitorFile(string path, ListBox listBox, ListBox listBox_Err, Hashtable ht, TextBox txt)
        {
            list_Info = listBox;
            list_Error = listBox_Err;
            imagePath = path;
            htCode = ht;
            txt_Num = txt;
            ftpArg = new FtpArg();
            ftpArg.FtpServerIP = ConfigurationSettings.AppSettings["FtpServerIP"];
            ftpArg.FtpUserID = ConfigurationSettings.AppSettings["FtpUserID"];
            ftpArg.FtpPassword = ConfigurationSettings.AppSettings["FtpPassword"];
            try
            {
                threadMonitor = null;
                string qualifiedPath = string.Format("{0}/合格", imagePath);
                string unQualifiedPath = string.Format("{0}/不合格", imagePath);
                htCode.Add("qualityID", 0);//初始化质量id，根据路径给值；
                if (!Directory.Exists(qualifiedPath))
                    Directory.CreateDirectory(qualifiedPath);
                if (!Directory.Exists(unQualifiedPath))
                    Directory.CreateDirectory(unQualifiedPath);
                threadMonitor = new Thread(monitor);
                threadMonitor.IsBackground = true;
                threadMonitor.Start();
                ShowMsg.showMsg(list_Info, "开始监控指定图片目录:" + imagePath);
                CheckList = new List<string>();
            }
            catch (Exception ex)
            {
                ShowMsg.showMsg(list_Error, DateTime.Now + " " + ex.Message, 3);//把错误单独摘出来放进一个list
            }
        }


        public static void monitor()
        {
            try
            {
                if (watcher != null)
                {
                    watcher.Dispose();
                }
                watcher = new FileSystemWatcher(imagePath);
                watcher.EnableRaisingEvents = true;
                watcher.Created += new FileSystemEventHandler(OnCreated);
                watcher.Deleted += new FileSystemEventHandler(OnDeleted);
                watcher.Renamed += new RenamedEventHandler(OnRenamed);
                watcher.IncludeSubdirectories = true;
            }
            catch (Exception ex)
            {
                ShowMsg.showMsg(list_Error, DateTime.Now + "" + ex.Message, 3);
            }
        }

        private static void OnCreated(object sender, FileSystemEventArgs e)
        {
            Thread.Sleep(100);
            string debug = string.Format("检测到新文件，{0}:{1}", e.ChangeType, e.Name);
            string file = Path.GetFileName(e.FullPath);
            if (!e.Name.Contains("合格"))
            {
                ShowMsg.showMsg(list_Error, DateTime.Now + " 员工编号：" + GetUserInfo.UserNum + " 请将文件上传到监控路径下的任意文件夹内！");
            }
            else
            {
                CheckList.Add(Path.GetFileNameWithoutExtension(e.Name));
                upload(e.FullPath);
                operationFlag = 1;
            }
        }

        #region 一些违规操作的记录
        private static void OnDeleted(object sender, FileSystemEventArgs e)
        {
            string debug = string.Format("{0}:{1}", e.ChangeType, e.Name);
            if (operationFlag < 1)
            {
                MessageBox.Show("该操作属于违规操作，您的操作已被记录！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                debug = string.Format("{0}-{1}:{2}", "操作员:" + GetUserInfo.UserNum + "进行了违规删除操作，具体动作为", e.ChangeType, e.Name);
            }
            //logger.Warn(debug);
            ShowMsg.showMsg(list_Info, debug, 2);
        }
        private static void OnRenamed(object sender, RenamedEventArgs e)
        {
            string debug = string.Format("{0}:{1}", e.ChangeType, e.Name);
            if (operationFlag < 1)
            {
                MessageBox.Show("该操作属于违规操作，您的操作已被记录！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                debug = string.Format("{0}-{1}:{2}", "操作员:" + GetUserInfo.UserNum + "进行了违规重命名操作，具体动作为", e.ChangeType, e.Name);
            }
            //logger.Warn(debug);
            ShowMsg.showMsg(list_Info, debug, 2);
        }
        #endregion

        /// <summary>
        /// 大批量上传
        /// </summary>
        public static void bulkUpload(string path, ListBox listBox, ListBox listBox_Err, Hashtable ht, TextBox txt, List<string> _CheckList, int _times = 1)
        {
            list_Info = listBox;
            list_Error = listBox_Err;
            imagePath = path;
            htCode = ht;
            txt_Num = txt;
            times = _times;
            CheckList = _CheckList;
            ftpArg = new FtpArg();
            ftpArg.FtpServerIP = ConfigurationSettings.AppSettings["FtpServerIP"];
            ftpArg.FtpUserID = ConfigurationSettings.AppSettings["FtpUserID"];
            ftpArg.FtpPassword = ConfigurationSettings.AppSettings["FtpPassword"];
            try
            {
                num = 0;
                cnt = 1;
                if (path.Contains("合格"))
                {
                    threadBulk = new Thread(Bulk);
                    threadBulk.IsBackground = true;
                    threadBulk.Start(1);
                    SocketInfo("start", "", new FtpArg());
                    if (times > 1)
                    {
                        Thread.Sleep(1000);
                        threadBulk2 = new Thread(Bulk);
                        threadBulk2.IsBackground = true;
                        threadBulk2.Start(2);
                    }
                    if (times > 2)
                    {
                        Thread.Sleep(1000);
                        threadBulk3 = new Thread(Bulk);
                        threadBulk3.IsBackground = true;
                        threadBulk3.Start(3);
                    }
                    if (times > 3)
                    {
                        Thread.Sleep(1000);
                        threadBulk4 = new Thread(Bulk);
                        threadBulk4.IsBackground = true;
                        threadBulk4.Start(4);
                    }
                }
                else
                {
                    ShowMsg.showMsg(list_Error, DateTime.Now + " 员工编号：" + GetUserInfo.UserNum + " 批量上传路径不合法，请将批量上传的文件拷贝到监控目录下的“合格”或“不合格”目录下");
                }
            }
            catch (Exception ex)
            {
                ShowMsg.showMsg(list_Error, ex.Message, 3);
            }
        }

        public static void Bulk(object _time)
        {            
            time = (int)_time;
            string _imagePath = imagePath + time.ToString();
            if (times == 1)
                _imagePath = imagePath;
            operationFlag = 1;
            List<FileInfo> files = PublicMethod.GetPicFiles((string)_imagePath);
            foreach (FileInfo file in files)
            {
                Thread.Sleep(100);
                upload(file.FullName, (int)_time);
                num++;
                getNumber(txt_Num, num);
            }
            getNumber(txt_Num, num, "-bulk ok" + _time.ToString());

            if ((int)_time == 1)
            {
                threadCheck = new Thread(CheckData);
                threadCheck.IsBackground = true;
                threadCheck.Start();
            }            
        }



        public static void upload(string filePath, int time = 1)
        {
            string file = Path.GetFileName(filePath);
            if (htFileList.Contains(file))
            {
                string warn = string.Format("该文件{0}已于{1}上传，无法重复上传", file, htFileList[file]);
                ShowMsg.showMsg(list_Error, warn, 2);
            }
            else
            {
                ShowMsg.showMsg(list_Info, "检测到新文件" + filePath);
                if (htFileList.Count > 10000)
                {
                    htFileList.Clear();
                }
                htFileList.Add(file, DateTime.Now);
                string filetype = Path.GetExtension(filePath);

                if (filetype == ".bmp" || filetype == ".jpg" || filetype == ".png")
                {
                    if (file.Contains("-"))
                    {
                        ShowMsg.showMsg(list_Error, DateTime.Now + " 文件名称不能含有‘-’" + file, 2);
                    }
                    else
                    {
                        try
                        {
                            string debug = string.Format("第{0}个文件:{1}", cnt, filePath);
                            ShowMsg.showMsg(list_Info, debug);
                            if (filePath.Contains("不合格"))
                                htCode["quality"] = "不合格";
                            else
                                htCode["quality"] = "合格";
                            string newFileName = Path.GetFileNameWithoutExtension(filePath) + "-" + htCode["quality"] + "-" + htCode["code"] + "-" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + filetype;//what a crazy filename! what a crazy leader!!;
                            Thread.Sleep(500);
                            int ret = SocketInfo(filePath, newFileName, ftpArg, time);
                            if (ret > 0)
                            {
                                string bakDir = Path.Combine(htCode["bakPath"].ToString(), DateTime.Now.ToString("yyyyMMdd") + "\\image\\" + htCode["quality"]);
                                if (!Directory.Exists(bakDir))
                                    Directory.CreateDirectory(bakDir);
                                string target = bakDir + "\\" + Path.GetFileNameWithoutExtension(filePath) + ".jpg";
                                if (File.Exists(target))
                                    File.Delete(target);
                                File.Move(filePath, target);
                            }
                            cnt++;
                        }
                        catch (Exception ex)
                        {
                            ShowMsg.showMsg(list_Error, DateTime.Now + " " + ex.Message, 3);
                        }
                    }
                }
                else
                {
                    ShowMsg.showMsg(list_Error, DateTime.Now + " 检测到文件不是图片文件" + file, 2);
                }
            }
        }

        /// <summary>
        /// 跟服务端进行socket通信（该方法写的不好，限制太多，难以复用）
        /// </summary>
        /// <param name="path"></param>
        /// <param name="newfilename"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static int SocketInfo(string path, string newfilename, FtpArg args, int _time = 1)
        {
            int ret = 0;
            Socket transferSocket = null;
            IPAddress ip = IPAddress.Parse(ConfigurationSettings.AppSettings["Server"].ToString());
            int end = _time - 1;
            int port = int.Parse(ConfigurationSettings.AppSettings["Port"].ToString()) + end;
            IPEndPoint ep = new IPEndPoint(ip, port);
            byte[] _buffer = new byte[102400];
            int _receiveCount = 0;
            string _receiveString = "";
            using (transferSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
            {
                try
                {
                    transferSocket.Connect(ep);
                    ShowMsg.showMsg(list_Info, "connect success...");
                    while (true)
                    {
                        _receiveCount = transferSocket.Receive(_buffer);
                        _receiveString = Encoding.UTF8.GetString(_buffer, 0, _receiveCount);
                        if (_receiveString == "yes")
                        {
                            if (path == "start")
                            {
                                string msg = string.Format("start|{0}|{1}", DateTime.Now.ToString("yyyyMMdd"), htCode["code"].ToString().Replace("-", "_"));
                                transferSocket.Send(Encoding.UTF8.GetBytes(msg));
                                break;
                            }
                            if (path == "check")
                            {
                                transferSocket.Send(Encoding.UTF8.GetBytes("check"));
                                break;
                            }
                            bool flag = FtpHelper.FtpUploadBroken(path, "", list_Info, list_Error, args);
                            if (flag)
                            {
                                string msg = string.Format("{0}|{1}|{2}| send ok!", GetUserInfo.UserNum, path, newfilename);
                                transferSocket.Send(Encoding.UTF8.GetBytes(msg));
                                Thread.Sleep(100);
                                ret = 1;
                            }
                            break;
                        }
                        else if (_receiveString.Contains("Repeat"))
                        {
                            string[] parts = _receiveString.Split('|');
                            string err = string.Format("重复的sn号码为：{0}", parts[1]);
                            string[] repeatFiles = parts[1].Split(';');
                            foreach (var repeat in repeatFiles)
                            {
                                if (string.IsNullOrEmpty(repeat))
                                    continue;
                                string repeatFile = System.Environment.CurrentDirectory + "\\RepeatLogs\\" + DateTime.Now.ToString("yyyyMMdd") + "_repeat.txt";
                                WriteInfo(repeatFile, repeat);
                            }
                            if (Convert.ToInt32(htCode["bulk"]) == 0)
                            {
                                string lastFile = path.Substring(0, path.Length - 4) + ".png";
                                FileInfo lastfi = new FileInfo(path);
                                lastfi.CopyTo(lastFile, true);
                                lastfi.Delete();
                            }
                            htFileList.Remove(Path.GetFileName(path));
                            int rc = parts[1].Split(';').Length - 1;
                            ShowMsg.showMsg(list_Error, DateTime.Now + " REPEAT WARNING:发现重复数据|" + rc + "|条未成功上传)。" + err, 3);
                            ShowMsg.showMsg(list_Info, DateTime.Now + "暂停3秒", 3); //心理安慰，实际停了4s
                            Thread.Sleep(4000);
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    ShowMsg.showMsg(list_Error, DateTime.Now + " 在socketinfo方法中发生 " + ex.Message, 3);
                    ret = -1;
                }
                finally
                {
                    ShowMsg.showMsg(list_Info, "server:" + transferSocket.RemoteEndPoint.ToString() + " disconnect...");
                    transferSocket.Close();
                    Thread.Sleep(100);
                }
            }
            return ret;
        }


        //批量上传结束后的验证        
        public static void CheckData()
        {
            if (CheckList.Count == 0)
                return;
            ShowMsg.showMsg(list_Info, "正在验证数据上传完整性，请稍后..." + DateTime.Now);
            Thread.Sleep(1000 * 5);
            ShowMsg.showMsg(list_Info, ".");
            Thread.Sleep(1000 * 5);
            ShowMsg.showMsg(list_Info, "..");
            Thread.Sleep(1000 * 5);
            ShowMsg.showMsg(list_Info, "...");
            Thread.Sleep(1000 * 5);
            ShowMsg.showMsg(list_Info, "....");
            Thread.Sleep(1000 * 5);
            ShowMsg.showMsg(list_Info, ".....");
            Thread.Sleep(1000 * 5);
            ShowMsg.showMsg(list_Info, "......");
            Thread.Sleep(1000 * 3);//休息30s,保证服务端的数据已经插入
            string reportFile = imagePath + "\\" + DateTime.Now.ToString("yyyyMMdd") + "_report.txt";    
            for (int i = 1; i <= times; i++)
            {
                SocketInfo("check", "", new FtpArg(), i);//发送一个check消息到服务端，确保本次的重复数据全部获取到
                Thread.Sleep(1000 * 2);
            }
            try
            {                            
                WriteInfo(reportFile, "------------------------------上传报告------------------------------");
                WriteInfo(reportFile, "报告时间：" + DateTime.Now);
                //先验重复
                ShowMsg.showMsg(list_Info, "正在获取服务器上记录的本次上传的重复文件sn号码");
                string remotePath = string.Format("repeatLog\\{0}_{1}_repeat.txt", DateTime.Now.ToString("yyyyMMdd"), htCode["code"].ToString().Replace('-', '_'));
                string repeatFile = FtpHelper.GetFile(remotePath, "repeat.txt", ftpArg, list_Info, list_Error);
                int repeatCnt = 0;
                if (!string.IsNullOrEmpty(repeatFile))
                {
                    if (repeatFile != "-1")
                    {
                        string path = System.Environment.CurrentDirectory + "\\RepeatLogs\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + "_repeat_ftp.txt";
                        if (File.Exists(path))
                            File.Delete(path);
                        FtpHelper.FtpDownloadBroken(repeatFile, "\\repeatLog\\", path, true, 0, ftpArg);
                        StreamReader sr = new StreamReader(path, System.Text.Encoding.UTF8);
                        String line;
                        WriteInfo(reportFile, "------------------------------重复记录------------------------------");
                        while ((line = sr.ReadLine()) != null)
                        {
                            ShowMsg.showMsg(list_Info, line);
                            WriteInfo(reportFile, "重复文件:" + line);//记录重复文件号码
                            if (!string.IsNullOrEmpty(line))
                            {
                                repeatCnt++;
                            }
                        }
                        num = num - repeatCnt;
                        sr.Close();
                    }
                    ShowMsg.showMsg(list_Info, "共计重复" + repeatCnt + "条");
                }
                //再验遗漏
                
                ImageManagerEntities ime = new ImageManagerEntities();
                List<string> retList = ime.ImageInfo.Where(u => CheckList.Contains(u.OriginPath)).Select(u => u.OriginPath).ToList();
                int total = CheckList.Count;
                List<string> checkFlagList = new List<string>();
                Hashtable htChack = new Hashtable();
                if (retList.Count == CheckList.Count)
                {
                    num = retList.Count;
                    ShowMsg.showMsg(list_Info, "本次上传没有遗漏数据");
                    PublicMethod.DelectDir(imagePath);
                }
                else
                {
                    WriteInfo(reportFile, "------------------------------遗漏记录------------------------------");
                    htFileList.Clear();
                    ShowMsg.showMsg(list_Info, "本次上传存在遗漏数据，列表如下");
                    CheckList = CheckList.Except(retList).ToList();//求两个list的差集
                    num = total - CheckList.Count;
                    if (RedisHelper.Get<List<string>>("checkBulk") == null)
                        RedisHelper.Set<List<string>>("checkBulk", CheckList, DateTime.Now.AddHours(12) - DateTime.Now);//这一步实乃不得已而为之，就是为了保证让redis库里有checkBulk这个键值对
                    checkFlagList = RedisHelper.Get<List<string>>("checkBulk");
                    checkFlagList.Clear();
                    string bakDir = Path.Combine(htCode["bakPath"].ToString(), DateTime.Now.ToString("yyyyMMdd") + "\\image\\" + htCode["quality"]);

                    foreach (var item in CheckList)
                    {
                        checkFlagList.Add(item);//写入临时list，Redis
                        ShowMsg.showMsg(list_Info, item);
                        string file = bakDir + "\\" + item + ".jpg";
                        if (File.Exists(file))
                        {
                            File.Move(file, imagePath + "\\" + item + ".jpg");
                        }
                        //WriteInfo(dropFile, file);
                        if(Path.GetFileName(file).Contains("-"))
                            WriteInfo(reportFile, "遗漏文件:" + file+",遗漏原因为主动遗漏，因文件名称不合法。");
                        else
                            WriteInfo(reportFile, "遗漏文件:" + file);
                    }
                    if (times > 1)
                    {
                        for (int i = 1; i <= times; i++)
                        {
                            string splitPath = imagePath + i.ToString();
                            PublicMethod.MoveFolderTo(splitPath, imagePath);
                        }
                    }
                    RedisHelper.DelKey("checkBulk");
                    RedisHelper.Set<List<string>>("checkBulk", checkFlagList, DateTime.Now.AddHours(12) - DateTime.Now);//将集差结果存入redis
                    ShowMsg.showMsg(list_Info, "共计：" + checkFlagList.Count + "条，已将未成功上传的文件放回原路径，并生成日志文件" + reportFile + "，请核对后重新上传");

                }
                ShowMsg.showMsg(list_Info, "------------------------------上传报告--------------------------------");
                ShowMsg.showMsg(list_Info, "1.共计上传了" + total + "条记录,成功了" + num + "条（包含重复）");
                ShowMsg.showMsg(list_Info, "2.有" + (repeatCnt + checkFlagList.Count()) + "条记录未上传，其中，重复" + repeatCnt + "条,遗漏" + checkFlagList.Count + "条");
                //if (checkFlagList.Count > 0)
                //    TryUploadAgain();
                getNumber(txt_Num, num, "-bulk ok");
                ShowMsg.showMsg(list_Info, "批量上传完成," + DateTime.Now);
                string reportmsg = "批量上传完成，\r\n 1.共计上传了" + total + "条记录,成功了" + num + "条（包含重复）\r\n 2.有" + (repeatCnt + checkFlagList.Count()) + "条记录未上传，其中，重复" + repeatCnt + "条,遗漏" + checkFlagList.Count + "条";
                WriteInfo(reportFile, "------------------------------报告总结------------------------------");
                WriteInfo(reportFile, "时间：" + DateTime.Now);
                WriteInfo(reportFile, reportmsg);
                WriteInfo(reportFile, "------------------------------本次报告结束------------------------------");
            }
            catch (Exception ex)
            {
                ShowMsg.showMsg(list_Error, "验证失败：" + ex.Message + "，此时请不要参考已上传数字，请到平台检索上传数量后在进行其他操作。");
                RedisHelper.Set<Hashtable>("htIntercept", null, DateTime.Now.AddHours(12) - DateTime.Now);
                RedisHelper.DelKey("checkBulk");
                WriteInfo(reportFile, "验证失败：" + ex.Message + "，此时请不要参考已上传数字，请到平台检索上传数量后在进行其他操作。");
            }
            WriteInfo(reportFile, "\r\n");
            operationFlag = 0;            
        }


        public static void TryUploadAgain()
        {
            ShowMsg.showMsg(list_Info, "正在尝试上传遗漏数据...");
            Thread.Sleep(2000);
            List<FileInfo> files = PublicMethod.GetPicFiles(imagePath);
            List<string> againList = new List<string>(files.Count);
            int againCnt = 0;
            foreach (FileInfo file in files)
            {
                upload(file.FullName);
                Thread.Sleep(100);
                againList.Add(Path.GetFileNameWithoutExtension(file.Name));
                againCnt++;
            }
            ImageManagerEntities ime = new ImageManagerEntities();
            List<string> retList = ime.ImageInfo.Where(u => againList.Contains(u.OriginPath)).Select(u => u.OriginPath).ToList();
            int total = retList.Count;
            if (total == againCnt)
            {
                ShowMsg.showMsg(list_Info, "遗漏数据上传完成,共计上传" + againCnt + "条");
            }
            else
            {
                ShowMsg.showMsg(list_Info, "仍存在遗漏数据" + (againCnt - total) + "条，请尝试手动上传");
                List<string> list = new List<string>();
                list = againList.Except(retList).ToList();
                RedisHelper.Set<List<string>>("checkBulk", list, DateTime.Now.AddHours(12) - DateTime.Now);//将集差结果存入redis
            }
        }

        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="path">路径</param>
        /// <param name="info">内容</param>
        private static void WriteInfo(string path, string info)
        {
            //if (!File.Exists(path))
            //{
            //    var myFile = File.Create(path);
            //    myFile.Close();
            //}
            //using (StreamWriter sw = File.AppendText(path))
            //{
            //    sw.WriteLine(info);
            //}
            File.AppendAllText(path, info + Environment.NewLine);
        }



        /// <summary>
        /// 关闭连接
        /// </summary>
        public static void CloseTcpSocket(ListBox listBox, ListBox listBox_Err)
        {
            list_Info = listBox;
            list_Error = listBox_Err;
            if (htCode != null && Convert.ToInt32(htCode["bulk"]) == 0)
            {
                if (MessageBox.Show("关闭连接会导致图片无法及时上传到图片服务器，确定要关闭链接吗？", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                {
                    if (threadMonitor != null)
                        threadMonitor.Abort();//关闭监控线程
                    if (watcher != null)
                        watcher.Dispose();
                }
            }
            if (threadBulk != null)
                threadBulk.Abort();
            if (threadBulk2 != null)
                threadBulk2.Abort();
            if (threadBulk3 != null)
                threadBulk3.Abort();
            if (threadBulk4 != null)
                threadBulk4.Abort();

            if (operationFlag > 0)//上传中途暂停，需要验证数据完整性
            {
                CheckData();
            }

            string msg = string.Format("员工编号为{0},关闭了上传通道", GetUserInfo.UserNum);
            ShowMsg.showMsg(list_Info, msg);
        }
    }
}